<template>
  <div class="content">
    <span>
      <el-form ref="editFormRef" :model="editForm" :rules="userRules">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="editForm.userName" disabled></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="editForm.age"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="editForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="职业" prop="occupation">
          <el-input v-model="editForm.occupation"></el-input>
        </el-form-item>
      </el-form>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle">取 消</el-button>
      <el-button type="primary" @click="submitUserForm">确 定</el-button>
    </span>
  </div>
</template>
<script>
import rules from '@/utils/rules'
export default {
  name: 'userDetail',
  props: {
    userDetail: Object,
  },
  mounted: {},
  data() {
    return {
      editForm: {
        userName: '',
        age: 0,
        phone: '',
        occupation: '',
        index: 0,
        pageNo: 1,
      },
      userRules: {
        userName: [
          {
            required: true,
            trigger: 'blur',
            validator: rules.FormValidate.Form().loginNameReg,
          },
        ],
        phone: [
          {
            required: true,
            trigger: 'blur',
            validator: rules.FormValidate.Form().validatePhone,
          },
        ],
      },
    }
  },
  created() {
    this.editForm = this.userDetail
  },
  methods: {
    cancle() {
      this.$emit('cancle')
    },
    submitUserForm() {
      this.$refs.editFormRef.validate((valid) => {
        console.log('合法情况' + valid)
        if (!valid) {
          return
        }
        console.log('提交用户详情:' + this.editForm)
        this.$emit('submitData', this.editForm)
      })
    },
  },
}
</script>
<style lang="scss">
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
</style>
